// components/order.js

// 使用微信小程序的格式化方法
Component({
  properties: {
    orderid: {
      type: String,
      value: ''
    },
    paymentMethod: {
      type: String,
      value: ''
    },
    totalPrice: {
      type: Number,
      value: 0
    },
    createdAt: {
      type: String,
      value: '',
      observer: function(newVal) {
        // 格式化日期
        this.setData({
          formattedcreatedAt: this.formatDate(newVal)
        });
      }
    },
    address: {
      type: String,
      value: ''
    },
    notes: {
      type: String,
      value: ''
    },
    orderdetailList: {
      type: Array,
      value: []
    }
  },
  data: {
    formattedcreatedAt: ''
  },
  methods: {
    formatDate(dateString) {
      const date = new Date(dateString);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      const seconds = date.getSeconds().toString().padStart(2, '0');
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    getStatus(status) {
      switch (status) {
        case '1':
          return "服务中";
        case '2':
          return "完成";
        case '0':
          return "待接单";
        case '-1':
          return "已取消";
        default:
          return "未知";
      }
    },
    onLoad(options) {
      console.log(this.data);
  
    },
  }
});

